<!--<?php
print <<<EOT
-->
<div class="m">
</div>
<!--
EOT;
if(!$action){
print <<<EOT
-->
<div class="t">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="tr4">
    <td>
<form action="$basename" method="post">
  <input name="filename" type="text" class="input" id="filename">
  <input name="directory" type="hidden" id="directory" value="$path">
  <input name="action" type="hidden" id="action" value="mkdir">
  <input type="submit" name="Submit" value="建立新文件夹" class="btn">
  <input type="button" name="Submit2" value="创建新模板" class="btn" onClick="window.location='$basename&action=new&directory=$path';">
</form>	</td>
  </tr>
</table>
</div>
<div class="t">
<table width="100%" border="0" cellspacing="0" cellpadding="0" id='filetable'>
  <tr class="head">
    <td colspan="5">用户模板管理</td>
    </tr>
  <tr class="tr2">
    <td width="5%">&nbsp;</td>
    <td>文件名</td>
    <td>文件大小</td>
    <td>修改时间</td>
    <td>管理</td>
  </tr>
<tr class="tr3">
  <td colspan="5"><a href="$basename&directory=$path&job=up"><img src="images/admin/file/updir.gif" width="16" height="16" align="absmiddle" />上一级目录</a></td>
</tr>
<!--
EOT;
$i=0;
foreach($files as $file){
$i++;
print <<<EOT
-->
  <tr class="tr3" id="tr$i">
    <td colspan="2"><img src="$file[icon]" width="16" height="16" hspace="5" align="absmiddle" />
	<span id='td$i'><a href="$file[url]"><span id='name$i'>$file[name]</span></a></span></td>
    <td>$file[size]<br /></td>
    <td>$file[time]<br /></td>
    <td>
		<a href="javascript:void(0);" onClick="return reName($i);"><img src="images/admin/rename.gif" align="absmiddle" alt="改名" /></a> 
		<a href="javascript:void(0);" onClick="return removeFile($i);"><img src="images/admin/delete.png" align="absmiddle" alt="删除" /></a>
	</td>
  </tr>
<!--
EOT;
}print <<<EOT
-->
</table>
</div>
<div id="renameok" style="color:white;background-color:blue;position:absolute;padding:5px;display:none;top:100px; left:100px;"><label id="operationInfo" style="display:block;color:#FFF;"></label></div>
<script language="javascript">
var path = '$path';
var http = new ActiveXObject("Microsoft.XMLHTTP")
var rename=function(){document.getElementById('renameok').style.display='none';}
var isdir = 0;

function removeFile(id){
	var name = document.getElementById("name"+id);
	var filename = name.innerHTML;
	if(filename.indexOf('.htm')==-1){
		alert('警告：如果删除目录，目录下包含的所有文件都会被删除！\\n\\n如果确认要删除目录，请FTP操作。');
		return false;
	}
	var msg=confirm("您确认要删除此模板么?");
	if(!msg) return false;
	window.location="$basename&action=del&path=$path&file="+filename;
	return false;
}

function reName(id){
	var idName = 'name'+id;
	var tdName = 'td'+id;
	var name = document.getElementById(idName);
	var filename = name.innerHTML;
	if(filename.indexOf('.htm')==-1){
		//alert('是一个目录');
		isdir=1;
	}
	var td = document.getElementById(tdName);
	td.innerHTML="<input class='input' name='ajax_input' id='ajax_input' value="+filename+" onblur=\"submitName(this.value,'"+filename+"','"+id+"');\">";
	document.getElementById('ajax_input').focus();
	return false;
}

function submitName(newFileName,oldFileName,id){
	var tdid = 'td'+id;
	var td = document.getElementById(tdid);
	if(isdir){
		td.innerHTML="<a href='$basename&directory="+newFileName+"'><span id=\"name"+id+"\">"+newFileName+"</span></a>";
	}else{
		td.innerHTML="<a href='$basename&action=edit&file="+newFileName+"&path="+path+"'><span id=\"name"+id+"\">"+newFileName+"</span></a>";
	}
	var queryString = encodeURIComponent("filename") + "=" + encodeURIComponent(newFileName)+"&";
	queryString += encodeURIComponent("oldfilename") + "=" + encodeURIComponent(oldFileName)+"&";
	queryString += encodeURIComponent("action") + "=" + encodeURIComponent('rename')+"&";
	queryString += encodeURIComponent("path") + "=" + encodeURIComponent(path);

	var contentType = "application/x-www-form-urlencoded; charset=$charset";
	var url = "$basename";

	http.open("post", url, true);
	http.onreadystatechange = showStat;
	http.setRequestHeader("Content-Type", contentType);
	http.send(queryString);
}

function showStat(){
	if(http.readyState == 4){
		var res = http.responseText;
		if(res =='formaterror') {
			alert('文件名格式错误');
			window.location.reload();
		}else if(res == 'renamefail'){
			alert('文件无法重命名，请检查文件属性');
			window.location.reload();
		}else if(res =='ok'){
			var op = document.getElementById('renameok');
			document.getElementById('operationInfo').innerHTML='文件重命名成功';
			op.style.display='';
			setTimeout('rename()',600);
		}
	}

}

</script>
<!--
EOT;
}elseif($action=='edit'){
print <<<EOT
-->
<style>
.menu{position:absolute;background:#fff;border:1px solid #69788c;}
.menu td, .menu li{background:#e6f5ff;}
.menu li{list-style:none;padding:0;}
.menu a{display:block;padding:3px 15px 3px 15px}
.menu a:hover{background:#e6f5ff;text-decoration:none;color:#fff;}
.menu ul.ul1 li a{display:inline;padding:0} 
#colorbox{width:91px;height:78px;padding:3px 0 0 3px;overflow:hidden;}
#colorbox div{cursor:pointer;width:8px;height:8px;float:left;margin:0 3px 3px 0;border:1px #000 solid;font:0/8px arial}
</style>
<div class="menu" id="menu_editor" style="display:none;"></div>
<div id="showmenu" style="z-index:100;display:none;"></div> 
<script language="javascript" src="script/global.js"></script>
<form action="$basename" method="post" name="FORM">
<div class="t">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="head">
    <td>模板编辑 您正在编辑 $file</td>
  </tr>
  <tr class="line">
    <td></td>
    </tr>
  <tr class="tr3">
    <td style="text-align:center">$html</td>
  </tr>
</table>

</div>
<div class="sub">
<input type="submit" name="Submit3" value="保存文件" class="btn">
<input name="filepath" type="hidden" id="filepath" value="$filepath">
<input name="action" type="hidden" id="action" value="$action"> 
<input name="step" type="hidden" id="step" value="2">
</div>
</form>
<!--
EOT;
}elseif($action=='new'){
print <<<EOT
-->
<style>
.menu{position:absolute;background:#fff;border:1px solid #69788c;}
.menu td, .menu li{background:#e6f5ff;}
.menu li{list-style:none;padding:0;}
.menu a{display:block;padding:3px 15px 3px 15px}
.menu a:hover{background:#e6f5ff;text-decoration:none;color:#fff;}
.menu ul.ul1 li a{display:inline;padding:0} 
#colorbox{width:91px;height:78px;padding:3px 0 0 3px;overflow:hidden;}
#colorbox div{cursor:pointer;width:8px;height:8px;float:left;margin:0 3px 3px 0;border:1px #000 solid;font:0/8px arial}
</style>
<div class="menu" id="menu_editor" style="display:none;"></div>
<div id="showmenu" style="z-index:100;display:none;"></div> 
<script language="javascript" src="script/global.js"></script>
<form action="$basename" method="post" name="FORM">
<div class="t">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr class="head">
    <td>新建模板</td>
  </tr>
  <tr class="line">
    <td>文件名:
      <input name="filename" type="text" id="filename" class="input" />
      .htm(文件格式只能是htm后缀,新建文件时不需要自己填写,系统自动命名)</td>
    </tr>
  <tr class="tr3">
    <td style="text-align:center">$html
      </td>
  </tr>
</table>

</div>
<div class="sub">
<input type="submit" name="Submit3" value="保存文件" class="btn">
<input name="path" type="hidden" id="path" value="$directory">
<input name="action" type="hidden" id="action" value="$action"> 
<input name="step" type="hidden" id="step" value="2">
</div>
</form>
<!--
EOT;
}
?>-->